﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Cfg;
using NHibernate;

namespace CommonShop.Service.Helper
{
    public class FluentSessionFactory
    {
        public static ISessionFactory GetCurrentFactory()
        {
            if (sessionFactory == null)
            {
                sessionFactory = CreateSessionFactory();
            }

            return sessionFactory;
        }

        private static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(MySQLConfiguration
               .Standard
               .ConnectionString(c => c.FromConnectionStringWithKey("Conn")))
                .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(FluentSessionFactory).Assembly).ExportTo(@"D:\tools"))
                .BuildSessionFactory();
        }

        private static ISessionFactory sessionFactory
        {
            get;
            set;
        }
    }
}
